﻿using System;

namespace ECommerce.Administration.Controls
{
	public partial class EditProductTag : AdminBaseUsercontrol
	{
		private Service.IProductTagService _ProductTagService;

		protected void Page_Load(object sender, EventArgs e)
		{
			if (SiteContext.Current == null)
			{
				Server.Transfer("~Administration/AdminLogin.aspx");
			}

			if (!IsPostBack)
			{
				LabelEditProductTagTitle.Text = GetLocalResourceString("Admin.EditProductTag.Add.Title");
				ButtonSave.Text = GetLocalResourceString("Admin.SaveButtonText");
			}

		}

		protected void ButtonSave_Click(object sender, EventArgs e)
		{
			if (SiteContext.Current.WorkingLanguage != null)
			{
				var theProductTag = new Data.Entity.ProductTag();

				theProductTag.Name = TextProductTagName.Text;
				theProductTag.LanguageID = SiteContext.Current.WorkingLanguage.LanguageId;
				theProductTag.ProductCount = 0;

				if (_ProductTagService == null)
				{
					_ProductTagService = new Service.ProductTagService();
				}

				_ProductTagService.CreateNewProductTag(theProductTag);
			}
		}
	}
}